import numpy as np
from math import sqrt


def mean_square_error(y_true, y_predict):
    assert len(y_true) == len(y_predict), "len must be equal"

    return np.sum((y_true - y_predict) ** 2) / len(y_true)


def root_mean_square_error(y_true, y_predict):
    return sqrt(mean_square_error(y_true, y_predict))


def mean_absolute_error(y_true, y_predict):
    return np.sum(np.absolute(y_true - y_predict)) / len(y_true)


def r2_score(y_true, y_predict):
    return 1 - mean_square_error(y_true, y_predict) / np.var(y_true)
